home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / KIUO1O (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  21.2 KB  |  913 lines

  1. package com.sun.java.swing;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.Point;
  11. import java.awt.Rectangle;
  12. import java.awt.Shape;
  13. import java.awt.Toolkit;
  14. import java.awt.Window;
  15. import java.awt.image.FilteredImageSource;
  16. import java.awt.image.ImageObserver;
  17. import java.awt.image.ImageProducer;
  18. import java.io.PrintStream;
  19.  
  20. public class DebugGraphics extends Graphics {
  21.    Graphics graphics;
  22.    Image buffer;
  23.    int debugOptions;
  24.    int graphicsID;
  25.    int xOffset;
  26.    int yOffset;
  27.    private static int graphicsCount = 0;
  28.    public static final int LOG_OPTION = 1;
  29.    public static final int FLASH_OPTION = 2;
  30.    public static final int BUFFERED_OPTION = 4;
  31.    public static final int NONE_OPTION = -1;
  32.    private static final Class debugGraphicsInfoKey;
  33.    static Class class$com$sun$java$swing$DebugGraphicsInfo;
  34.  
  35.    static {
  36.       Class var10000 = class$com$sun$java$swing$DebugGraphicsInfo;
  37.       if (var10000 == null) {
  38.          try {
  39.             var10000 = Class.forName("com.sun.java.swing.DebugGraphicsInfo");
  40.          } catch (ClassNotFoundException var0) {
  41.             throw new NoClassDefFoundError(((Throwable)var0).getMessage());
  42.          }
  43.  
  44.          class$com$sun$java$swing$DebugGraphicsInfo = var10000;
  45.       }
  46.  
  47.       debugGraphicsInfoKey = var10000;
  48.    }
  49.  
  50.    public DebugGraphics() {
  51.       this.graphicsID = graphicsCount++;
  52.       this.buffer = null;
  53.       this.xOffset = this.yOffset = 0;
  54.    }
  55.  
  56.    public DebugGraphics(Graphics graphics) {
  57.       this();
  58.       this.graphics = graphics;
  59.    }
  60.  
  61.    public DebugGraphics(Graphics graphics, JComponent component) {
  62.       this(graphics);
  63.       this.setDebugOptions(component.shouldDebugGraphics());
  64.    }
  65.  
  66.    public void clearRect(int x, int y, int width, int height) {
  67.       DebugGraphicsInfo info = info();
  68.       if (this.debugLog()) {
  69.          info().log(this.toShortString() + " Clearing rect: " + new Rectangle(x, y, width, height));
  70.       }
  71.  
  72.       if (this.isDrawingBuffer()) {
  73.          if (this.debugBuffered()) {
  74.             Graphics debugGraphics = this.debugGraphics();
  75.             debugGraphics.clearRect(x, y, width, height);
  76.             debugGraphics.dispose();
  77.          }
  78.       } else if (this.debugFlash()) {
  79.          Color oldColor = this.getColor();
  80.          int count = info.flashCount * 2 - 1;
  81.  
  82.          for(int i = 0; i < count; ++i) {
  83.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  84.             this.graphics.clearRect(x, y, width, height);
  85.             Toolkit.getDefaultToolkit().sync();
  86.             this.sleep(info.flashTime);
  87.          }
  88.  
  89.          this.graphics.setColor(oldColor);
  90.       }
  91.  
  92.       this.graphics.clearRect(x, y, width, height);
  93.    }
  94.  
  95.    public void clipRect(int x, int y, int width, int height) {
  96.       this.graphics.clipRect(x, y, width, height);
  97.       if (this.debugLog()) {
  98.          info().log(this.toShortString() + " Setting clipRect: " + new Rectangle(x, y, width, height) + " New clipRect: " + this.graphics.getClip());
  99.       }
  100.  
  101.    }
  102.  
  103.    public void copyArea(int x, int y, int width, int height, int destX, int destY) {
  104.       if (this.debugLog()) {
  105.          info().log(this.toShortString() + " Copying area from: " + new Rectangle(x, y, width, height) + " to: " + new Point(destX, destY));
  106.       }
  107.  
  108.       this.graphics.copyArea(x, y, width, height, destX, destY);
  109.    }
  110.  
  111.    public Graphics create() {
  112.       DebugGraphics debugGraphics = new DebugGraphics();
  113.       debugGraphics.graphics = this.graphics.create();
  114.       debugGraphics.debugOptions = this.debugOptions;
  115.       debugGraphics.buffer = this.buffer;
  116.       return debugGraphics;
  117.    }
  118.  
  119.    public Graphics create(int x, int y, int width, int height) {
  120.       DebugGraphics debugGraphics = new DebugGraphics();
  121.       debugGraphics.graphics = SwingGraphics.createGraphics(this.graphics, x, y, width, height);
  122.       debugGraphics.debugOptions = this.debugOptions;
  123.       debugGraphics.buffer = this.buffer;
  124.       debugGraphics.xOffset = this.xOffset + x;
  125.       debugGraphics.yOffset = this.yOffset + y;
  126.       return debugGraphics;
  127.    }
  128.  
  129.    boolean debugBuffered() {
  130.       return (this.debugOptions & 4) == 4;
  131.    }
  132.  
  133.    static int debugComponentCount() {
  134.       DebugGraphicsInfo debugGraphicsInfo = info();
  135.       return debugGraphicsInfo != null && debugGraphicsInfo.componentToDebug != null ? debugGraphicsInfo.componentToDebug.size() : 0;
  136.    }
  137.  
  138.    boolean debugFlash() {
  139.       return (this.debugOptions & 2) == 2;
  140.    }
  141.  
  142.    private Graphics debugGraphics() {
  143.       DebugGraphicsInfo info = info();
  144.       if (info.debugFrame == null) {
  145.          info.debugFrame = new JFrame();
  146.          info.debugFrame.setSize(500, 500);
  147.       }
  148.  
  149.       JFrame debugFrame = info.debugFrame;
  150.       ((Window)debugFrame).show();
  151.       DebugGraphics debugGraphics = new DebugGraphics(((Component)debugFrame).getGraphics());
  152.       debugGraphics.setFont(this.getFont());
  153.       debugGraphics.setColor(this.getColor());
  154.       debugGraphics.translate(this.xOffset, this.yOffset);
  155.       debugGraphics.setClip(this.getClipBounds());
  156.       if (this.debugFlash()) {
  157.          debugGraphics.setDebugOptions(2);
  158.       }
  159.  
  160.       return debugGraphics;
  161.    }
  162.  
  163.    boolean debugLog() {
  164.       return (this.debugOptions & 1) == 1;
  165.    }
  166.  
  167.    public void dispose() {
  168.       this.graphics.dispose();
  169.       this.graphics = null;
  170.    }
  171.  
  172.    public void draw3DRect(int x, int y, int width, int height, boolean raised) {
  173.       DebugGraphicsInfo info = info();
  174.       if (this.debugLog()) {
  175.          info().log(this.toShortString() + " Drawing 3D rect: " + new Rectangle(x, y, width, height) + " Raised bezel: " + raised);
  176.       }
  177.  
  178.       if (this.isDrawingBuffer()) {
  179.          if (this.debugBuffered()) {
  180.             Graphics debugGraphics = this.debugGraphics();
  181.             debugGraphics.draw3DRect(x, y, width, height, raised);
  182.             debugGraphics.dispose();
  183.          }
  184.       } else if (this.debugFlash()) {
  185.          Color oldColor = this.getColor();
  186.          int count = info.flashCount * 2 - 1;
  187.  
  188.          for(int i = 0; i < count; ++i) {
  189.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  190.             this.graphics.draw3DRect(x, y, width, height, raised);
  191.             Toolkit.getDefaultToolkit().sync();
  192.             this.sleep(info.flashTime);
  193.          }
  194.  
  195.          this.graphics.setColor(oldColor);
  196.       }
  197.  
  198.       this.graphics.draw3DRect(x, y, width, height, raised);
  199.    }
  200.  
  201.    public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
  202.       DebugGraphicsInfo info = info();
  203.       if (this.debugLog()) {
  204.          info().log(this.toShortString() + " Drawing arc: " + new Rectangle(x, y, width, height) + " startAngle: " + startAngle + " arcAngle: " + arcAngle);
  205.       }
  206.  
  207.       if (this.isDrawingBuffer()) {
  208.          if (this.debugBuffered()) {
  209.             Graphics debugGraphics = this.debugGraphics();
  210.             debugGraphics.drawArc(x, y, width, height, startAngle, arcAngle);
  211.             debugGraphics.dispose();
  212.          }
  213.       } else if (this.debugFlash()) {
  214.          Color oldColor = this.getColor();
  215.          int count = info.flashCount * 2 - 1;
  216.  
  217.          for(int i = 0; i < count; ++i) {
  218.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  219.             this.graphics.drawArc(x, y, width, height, startAngle, arcAngle);
  220.             Toolkit.getDefaultToolkit().sync();
  221.             this.sleep(info.flashTime);
  222.          }
  223.  
  224.          this.graphics.setColor(oldColor);
  225.       }
  226.  
  227.       this.graphics.drawArc(x, y, width, height, startAngle, arcAngle);
  228.    }
  229.  
  230.    public void drawBytes(byte[] data, int offset, int length, int x, int y) {
  231.       DebugGraphicsInfo info = info();
  232.       this.graphics.getFont();
  233.       if (this.debugLog()) {
  234.          info().log(this.toShortString() + " Drawing bytes at: " + new Point(x, y));
  235.       }
  236.  
  237.       if (this.isDrawingBuffer()) {
  238.          if (this.debugBuffered()) {
  239.             Graphics debugGraphics = this.debugGraphics();
  240.             debugGraphics.drawBytes(data, offset, length, x, y);
  241.             debugGraphics.dispose();
  242.          }
  243.       } else if (this.debugFlash()) {
  244.          Color oldColor = this.getColor();
  245.          int count = info.flashCount * 2 - 1;
  246.  
  247.          for(int i = 0; i < count; ++i) {
  248.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  249.             this.graphics.drawBytes(data, offset, length, x, y);
  250.             Toolkit.getDefaultToolkit().sync();
  251.             this.sleep(info.flashTime);
  252.          }
  253.  
  254.          this.graphics.setColor(oldColor);
  255.       }
  256.  
  257.       this.graphics.drawBytes(data, offset, length, x, y);
  258.    }
  259.  
  260.    public void drawChars(char[] data, int offset, int length, int x, int y) {
  261.       DebugGraphicsInfo info = info();
  262.       this.graphics.getFont();
  263.       if (this.debugLog()) {
  264.          info().log(this.toShortString() + " Drawing chars at " + new Point(x, y));
  265.       }
  266.  
  267.       if (this.isDrawingBuffer()) {
  268.          if (this.debugBuffered()) {
  269.             Graphics debugGraphics = this.debugGraphics();
  270.             debugGraphics.drawChars(data, offset, length, x, y);
  271.             debugGraphics.dispose();
  272.          }
  273.       } else if (this.debugFlash()) {
  274.          Color oldColor = this.getColor();
  275.          int count = info.flashCount * 2 - 1;
  276.  
  277.          for(int i = 0; i < count; ++i) {
  278.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  279.             this.graphics.drawChars(data, offset, length, x, y);
  280.             Toolkit.getDefaultToolkit().sync();
  281.             this.sleep(info.flashTime);
  282.          }
  283.  
  284.          this.graphics.setColor(oldColor);
  285.       }
  286.  
  287.       this.graphics.drawChars(data, offset, length, x, y);
  288.    }
  289.  
  290.    public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) {
  291.       return this.graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
  292.    }
  293.  
  294.    public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {
  295.       return this.graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
  296.    }
  297.  
  298.    public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
  299.       return this.graphics.drawImage(img, x, y, width, height, bgcolor, observer);
  300.    }
  301.  
  302.    public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
  303.       return this.graphics.drawImage(img, x, y, width, height, observer);
  304.    }
  305.  
  306.    public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
  307.       return this.graphics.drawImage(img, x, y, bgcolor, observer);
  308.    }
  309.  
  310.    public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
  311.       DebugGraphicsInfo info = info();
  312.       if (this.debugLog()) {
  313.          info().log(this.toShortString() + " Drawing image: " + img + " at: " + new Point(x, y));
  314.       }
  315.  
  316.       if (this.isDrawingBuffer()) {
  317.          if (this.debugBuffered()) {
  318.             Graphics debugGraphics = this.debugGraphics();
  319.             debugGraphics.drawImage(img, x, y, observer);
  320.             debugGraphics.dispose();
  321.          }
  322.       } else if (this.debugFlash()) {
  323.          int count = info.flashCount * 2 - 1;
  324.          ImageProducer oldProducer = img.getSource();
  325.          ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor));
  326.          Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer);
  327.          DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();
  328.  
  329.          for(int i = 0; i < count; ++i) {
  330.             this.graphics.drawImage(i % 2 == 0 ? newImage : img, x, y, imageObserver);
  331.             Toolkit.getDefaultToolkit().sync();
  332.  
  333.             while(!imageObserver.allBitsPresent() && !imageObserver.imageHasProblem()) {
  334.                this.sleep(10);
  335.             }
  336.  
  337.             this.sleep(info.flashTime);
  338.          }
  339.       }
  340.  
  341.       return this.graphics.drawImage(img, x, y, observer);
  342.    }
  343.  
  344.    public void drawLine(int x1, int y1, int x2, int y2) {
  345.       DebugGraphicsInfo info = info();
  346.       if (this.debugLog()) {
  347.          info().log(this.toShortString() + " Drawing line: from " + this.pointToString(x1, y1) + " to " + this.pointToString(x2, y2));
  348.       }
  349.  
  350.       if (this.isDrawingBuffer()) {
  351.          if (this.debugBuffered()) {
  352.             Graphics debugGraphics = this.debugGraphics();
  353.             debugGraphics.drawLine(x1, y1, x2, y2);
  354.             debugGraphics.dispose();
  355.          }
  356.       } else if (this.debugFlash()) {
  357.          Color oldColor = this.getColor();
  358.          int count = info.flashCount * 2 - 1;
  359.  
  360.          for(int i = 0; i < count; ++i) {
  361.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  362.             this.graphics.drawLine(x1, y1, x2, y2);
  363.             Toolkit.getDefaultToolkit().sync();
  364.             this.sleep(info.flashTime);
  365.          }
  366.  
  367.          this.graphics.setColor(oldColor);
  368.       }
  369.  
  370.       this.graphics.drawLine(x1, y1, x2, y2);
  371.    }
  372.  
  373.    public void drawOval(int x, int y, int width, int height) {
  374.       DebugGraphicsInfo info = info();
  375.       if (this.debugLog()) {
  376.          info().log(this.toShortString() + " Drawing oval: " + new Rectangle(x, y, width, height));
  377.       }
  378.  
  379.       if (this.isDrawingBuffer()) {
  380.          if (this.debugBuffered()) {
  381.             Graphics debugGraphics = this.debugGraphics();
  382.             debugGraphics.drawOval(x, y, width, height);
  383.             debugGraphics.dispose();
  384.          }
  385.       } else if (this.debugFlash()) {
  386.          Color oldColor = this.getColor();
  387.          int count = info.flashCount * 2 - 1;
  388.  
  389.          for(int i = 0; i < count; ++i) {
  390.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  391.             this.graphics.drawOval(x, y, width, height);
  392.             Toolkit.getDefaultToolkit().sync();
  393.             this.sleep(info.flashTime);
  394.          }
  395.  
  396.          this.graphics.setColor(oldColor);
  397.       }
  398.  
  399.       this.graphics.drawOval(x, y, width, height);
  400.    }
  401.  
  402.    public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
  403.       DebugGraphicsInfo info = info();
  404.       if (this.debugLog()) {
  405.          info().log(this.toShortString() + " Drawing polygon: " + " nPoints: " + nPoints + " X's: " + xPoints + " Y's: " + yPoints);
  406.       }
  407.  
  408.       if (this.isDrawingBuffer()) {
  409.          if (this.debugBuffered()) {
  410.             Graphics debugGraphics = this.debugGraphics();
  411.             debugGraphics.drawPolygon(xPoints, yPoints, nPoints);
  412.             debugGraphics.dispose();
  413.          }
  414.       } else if (this.debugFlash()) {
  415.          Color oldColor = this.getColor();
  416.          int count = info.flashCount * 2 - 1;
  417.  
  418.          for(int i = 0; i < count; ++i) {
  419.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  420.             this.graphics.drawPolygon(xPoints, yPoints, nPoints);
  421.             Toolkit.getDefaultToolkit().sync();
  422.             this.sleep(info.flashTime);
  423.          }
  424.  
  425.          this.graphics.setColor(oldColor);
  426.       }
  427.  
  428.       this.graphics.drawPolygon(xPoints, yPoints, nPoints);
  429.    }
  430.  
  431.    public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
  432.       DebugGraphicsInfo info = info();
  433.       if (this.debugLog()) {
  434.          info().log(this.toShortString() + " Drawing polyline: " + " nPoints: " + nPoints + " X's: " + xPoints + " Y's: " + yPoints);
  435.       }
  436.  
  437.       if (this.isDrawingBuffer()) {
  438.          if (this.debugBuffered()) {
  439.             Graphics debugGraphics = this.debugGraphics();
  440.             debugGraphics.drawPolyline(xPoints, yPoints, nPoints);
  441.             debugGraphics.dispose();
  442.          }
  443.       } else if (this.debugFlash()) {
  444.          Color oldColor = this.getColor();
  445.          int count = info.flashCount * 2 - 1;
  446.  
  447.          for(int i = 0; i < count; ++i) {
  448.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  449.             this.graphics.drawPolyline(xPoints, yPoints, nPoints);
  450.             Toolkit.getDefaultToolkit().sync();
  451.             this.sleep(info.flashTime);
  452.          }
  453.  
  454.          this.graphics.setColor(oldColor);
  455.       }
  456.  
  457.       this.graphics.drawPolyline(xPoints, yPoints, nPoints);
  458.    }
  459.  
  460.    public void drawRect(int x, int y, int width, int height) {
  461.       DebugGraphicsInfo info = info();
  462.       if (this.debugLog()) {
  463.          info().log(this.toShortString() + " Drawing rect: " + new Rectangle(x, y, width, height));
  464.       }
  465.  
  466.       if (this.isDrawingBuffer()) {
  467.          if (this.debugBuffered()) {
  468.             Graphics debugGraphics = this.debugGraphics();
  469.             debugGraphics.drawRect(x, y, width, height);
  470.             debugGraphics.dispose();
  471.          }
  472.       } else if (this.debugFlash()) {
  473.          Color oldColor = this.getColor();
  474.          int count = info.flashCount * 2 - 1;
  475.  
  476.          for(int i = 0; i < count; ++i) {
  477.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  478.             this.graphics.drawRect(x, y, width, height);
  479.             Toolkit.getDefaultToolkit().sync();
  480.             this.sleep(info.flashTime);
  481.          }
  482.  
  483.          this.graphics.setColor(oldColor);
  484.       }
  485.  
  486.       this.graphics.drawRect(x, y, width, height);
  487.    }
  488.  
  489.    public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
  490.       DebugGraphicsInfo info = info();
  491.       if (this.debugLog()) {
  492.          info().log(this.toShortString() + " Drawing round rect: " + new Rectangle(x, y, width, height) + " arcWidth: " + arcWidth + " archHeight: " + arcHeight);
  493.       }
  494.  
  495.       if (this.isDrawingBuffer()) {
  496.          if (this.debugBuffered()) {
  497.             Graphics debugGraphics = this.debugGraphics();
  498.             debugGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
  499.             debugGraphics.dispose();
  500.          }
  501.       } else if (this.debugFlash()) {
  502.          Color oldColor = this.getColor();
  503.          int count = info.flashCount * 2 - 1;
  504.  
  505.          for(int i = 0; i < count; ++i) {
  506.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  507.             this.graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
  508.             Toolkit.getDefaultToolkit().sync();
  509.             this.sleep(info.flashTime);
  510.          }
  511.  
  512.          this.graphics.setColor(oldColor);
  513.       }
  514.  
  515.       this.graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
  516.    }
  517.  
  518.    public void drawString(String aString, int x, int y) {
  519.       DebugGraphicsInfo info = info();
  520.       if (this.debugLog()) {
  521.          info().log(this.toShortString() + " Drawing string: \"" + aString + "\" at: " + new Point(x, y));
  522.       }
  523.  
  524.       if (this.isDrawingBuffer()) {
  525.          if (this.debugBuffered()) {
  526.             Graphics debugGraphics = this.debugGraphics();
  527.             debugGraphics.drawString(aString, x, y);
  528.             debugGraphics.dispose();
  529.          }
  530.       } else if (this.debugFlash()) {
  531.          Color oldColor = this.getColor();
  532.          int count = info.flashCount * 2 - 1;
  533.  
  534.          for(int i = 0; i < count; ++i) {
  535.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  536.             this.graphics.drawString(aString, x, y);
  537.             Toolkit.getDefaultToolkit().sync();
  538.             this.sleep(info.flashTime);
  539.          }
  540.  
  541.          this.graphics.setColor(oldColor);
  542.       }
  543.  
  544.       this.graphics.drawString(aString, x, y);
  545.    }
  546.  
  547.    public void fill3DRect(int x, int y, int width, int height, boolean raised) {
  548.       DebugGraphicsInfo info = info();
  549.       if (this.debugLog()) {
  550.          info().log(this.toShortString() + " Filling 3D rect: " + new Rectangle(x, y, width, height) + " Raised bezel: " + raised);
  551.       }
  552.  
  553.       if (this.isDrawingBuffer()) {
  554.          if (this.debugBuffered()) {
  555.             Graphics debugGraphics = this.debugGraphics();
  556.             debugGraphics.fill3DRect(x, y, width, height, raised);
  557.             debugGraphics.dispose();
  558.          }
  559.       } else if (this.debugFlash()) {
  560.          Color oldColor = this.getColor();
  561.          int count = info.flashCount * 2 - 1;
  562.  
  563.          for(int i = 0; i < count; ++i) {
  564.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  565.             this.graphics.fill3DRect(x, y, width, height, raised);
  566.             Toolkit.getDefaultToolkit().sync();
  567.             this.sleep(info.flashTime);
  568.          }
  569.  
  570.          this.graphics.setColor(oldColor);
  571.       }
  572.  
  573.       this.graphics.fill3DRect(x, y, width, height, raised);
  574.    }
  575.  
  576.    public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
  577.       DebugGraphicsInfo info = info();
  578.       if (this.debugLog()) {
  579.          info().log(this.toShortString() + " Filling arc: " + new Rectangle(x, y, width, height) + " startAngle: " + startAngle + " arcAngle: " + arcAngle);
  580.       }
  581.  
  582.       if (this.isDrawingBuffer()) {
  583.          if (this.debugBuffered()) {
  584.             Graphics debugGraphics = this.debugGraphics();
  585.             debugGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
  586.             debugGraphics.dispose();
  587.          }
  588.       } else if (this.debugFlash()) {
  589.          Color oldColor = this.getColor();
  590.          int count = info.flashCount * 2 - 1;
  591.  
  592.          for(int i = 0; i < count; ++i) {
  593.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  594.             this.graphics.fillArc(x, y, width, height, startAngle, arcAngle);
  595.             Toolkit.getDefaultToolkit().sync();
  596.             this.sleep(info.flashTime);
  597.          }
  598.  
  599.          this.graphics.setColor(oldColor);
  600.       }
  601.  
  602.       this.graphics.fillArc(x, y, width, height, startAngle, arcAngle);
  603.    }
  604.  
  605.    public void fillOval(int x, int y, int width, int height) {
  606.       DebugGraphicsInfo info = info();
  607.       if (this.debugLog()) {
  608.          info().log(this.toShortString() + " Filling oval: " + new Rectangle(x, y, width, height));
  609.       }
  610.  
  611.       if (this.isDrawingBuffer()) {
  612.          if (this.debugBuffered()) {
  613.             Graphics debugGraphics = this.debugGraphics();
  614.             debugGraphics.fillOval(x, y, width, height);
  615.             debugGraphics.dispose();
  616.          }
  617.       } else if (this.debugFlash()) {
  618.          Color oldColor = this.getColor();
  619.          int count = info.flashCount * 2 - 1;
  620.  
  621.          for(int i = 0; i < count; ++i) {
  622.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  623.             this.graphics.fillOval(x, y, width, height);
  624.             Toolkit.getDefaultToolkit().sync();
  625.             this.sleep(info.flashTime);
  626.          }
  627.  
  628.          this.graphics.setColor(oldColor);
  629.       }
  630.  
  631.       this.graphics.fillOval(x, y, width, height);
  632.    }
  633.  
  634.    public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
  635.       DebugGraphicsInfo info = info();
  636.       if (this.debugLog()) {
  637.          info().log(this.toShortString() + " Filling polygon: " + " nPoints: " + nPoints + " X's: " + xPoints + " Y's: " + yPoints);
  638.       }
  639.  
  640.       if (this.isDrawingBuffer()) {
  641.          if (this.debugBuffered()) {
  642.             Graphics debugGraphics = this.debugGraphics();
  643.             debugGraphics.fillPolygon(xPoints, yPoints, nPoints);
  644.             debugGraphics.dispose();
  645.          }
  646.       } else if (this.debugFlash()) {
  647.          Color oldColor = this.getColor();
  648.          int count = info.flashCount * 2 - 1;
  649.  
  650.          for(int i = 0; i < count; ++i) {
  651.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  652.             this.graphics.fillPolygon(xPoints, yPoints, nPoints);
  653.             Toolkit.getDefaultToolkit().sync();
  654.             this.sleep(info.flashTime);
  655.          }
  656.  
  657.          this.graphics.setColor(oldColor);
  658.       }
  659.  
  660.       this.graphics.fillPolygon(xPoints, yPoints, nPoints);
  661.    }
  662.  
  663.    public void fillRect(int x, int y, int width, int height) {
  664.       DebugGraphicsInfo info = info();
  665.       if (this.debugLog()) {
  666.          info().log(this.toShortString() + " Filling rect: " + new Rectangle(x, y, width, height));
  667.       }
  668.  
  669.       if (this.isDrawingBuffer()) {
  670.          if (this.debugBuffered()) {
  671.             Graphics debugGraphics = this.debugGraphics();
  672.             debugGraphics.fillRect(x, y, width, height);
  673.             debugGraphics.dispose();
  674.          }
  675.       } else if (this.debugFlash()) {
  676.          Color oldColor = this.getColor();
  677.          int count = info.flashCount * 2 - 1;
  678.  
  679.          for(int i = 0; i < count; ++i) {
  680.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  681.             this.graphics.fillRect(x, y, width, height);
  682.             Toolkit.getDefaultToolkit().sync();
  683.             this.sleep(info.flashTime);
  684.          }
  685.  
  686.          this.graphics.setColor(oldColor);
  687.       }
  688.  
  689.       this.graphics.fillRect(x, y, width, height);
  690.    }
  691.  
  692.    public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
  693.       DebugGraphicsInfo info = info();
  694.       if (this.debugLog()) {
  695.          info().log(this.toShortString() + " Filling round rect: " + new Rectangle(x, y, width, height) + " arcWidth: " + arcWidth + " archHeight: " + arcHeight);
  696.       }
  697.  
  698.       if (this.isDrawingBuffer()) {
  699.          if (this.debugBuffered()) {
  700.             Graphics debugGraphics = this.debugGraphics();
  701.             debugGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
  702.             debugGraphics.dispose();
  703.          }
  704.       } else if (this.debugFlash()) {
  705.          Color oldColor = this.getColor();
  706.          int count = info.flashCount * 2 - 1;
  707.  
  708.          for(int i = 0; i < count; ++i) {
  709.             this.graphics.setColor(i % 2 == 0 ? info.flashColor : oldColor);
  710.             this.graphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
  711.             Toolkit.getDefaultToolkit().sync();
  712.             this.sleep(info.flashTime);
  713.          }
  714.  
  715.          this.graphics.setColor(oldColor);
  716.       }
  717.  
  718.       this.graphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
  719.    }
  720.  
  721.    public static Color flashColor() {
  722.       return info().flashColor;
  723.    }
  724.  
  725.    public static int flashCount() {
  726.       return info().flashCount;
  727.    }
  728.  
  729.    public static int flashTime() {
  730.       return info().flashTime;
  731.    }
  732.  
  733.    public Shape getClip() {
  734.       return this.graphics.getClip();
  735.    }
  736.  
  737.    public Rectangle getClipBounds() {
  738.       return this.graphics.getClipBounds();
  739.    }
  740.  
  741.    public Color getColor() {
  742.       return this.graphics.getColor();
  743.    }
  744.  
  745.    public int getDebugOptions() {
  746.       return this.debugOptions;
  747.    }
  748.  
  749.    static int getDebugOptions(JComponent component) {
  750.       DebugGraphicsInfo debugGraphicsInfo = info();
  751.       return debugGraphicsInfo == null ? 0 : debugGraphicsInfo.getDebugOptions(component);
  752.    }
  753.  
  754.    public Font getFont() {
  755.       return this.graphics.getFont();
  756.    }
  757.  
  758.    public FontMetrics getFontMetrics() {
  759.       return this.graphics.getFontMetrics();
  760.    }
  761.  
  762.    public FontMetrics getFontMetrics(Font f) {
  763.       return this.graphics.getFontMetrics(f);
  764.    }
  765.  
  766.    static DebugGraphicsInfo info() {
  767.       DebugGraphicsInfo debugGraphicsInfo = (DebugGraphicsInfo)SwingUtilities.appContextGet(debugGraphicsInfoKey);
  768.       if (debugGraphicsInfo == null) {
  769.          debugGraphicsInfo = new DebugGraphicsInfo();
  770.          SwingUtilities.appContextPut(debugGraphicsInfoKey, debugGraphicsInfo);
  771.       }
  772.  
  773.       return debugGraphicsInfo;
  774.    }
  775.  
  776.    public boolean isDrawingBuffer() {
  777.       return this.buffer != null;
  778.    }
  779.  
  780.    public static PrintStream logStream() {
  781.       return info().stream;
  782.    }
  783.  
  784.    String pointToString(int x, int y) {
  785.       StringBuffer buffer = new StringBuffer("(" + x + ", " + y + ")");
  786.       return buffer.toString();
  787.    }
  788.  
  789.    public void setClip(int x, int y, int width, int height) {
  790.       this.graphics.setClip(x, y, width, height);
  791.       if (this.debugLog()) {
  792.          info().log(this.toShortString() + " Setting new clipRect: " + this.graphics.getClip());
  793.       }
  794.  
  795.    }
  796.  
  797.    public void setClip(Shape clip) {
  798.       this.graphics.setClip(clip);
  799.       if (this.debugLog()) {
  800.          info().log(this.toShortString() + " Setting new clipRect: " + this.graphics.getClip());
  801.       }
  802.  
  803.    }
  804.  
  805.    public void setColor(Color aColor) {
  806.       if (this.debugLog()) {
  807.          info().log(this.toShortString() + " Setting color: " + aColor);
  808.       }
  809.  
  810.       this.graphics.setColor(aColor);
  811.    }
  812.  
  813.    public void setDebugOptions(int options) {
  814.       if (options != 0) {
  815.          if (options == -1) {
  816.             if (this.debugOptions != 0) {
  817.                System.err.println(this.toShortString() + " Disabling debug");
  818.                this.debugOptions = 0;
  819.             }
  820.          } else if (this.debugOptions != options) {
  821.             this.debugOptions |= options;
  822.             if (this.debugLog()) {
  823.                System.err.println(this.toShortString() + " Enabling debug");
  824.             }
  825.          }
  826.       }
  827.  
  828.    }
  829.  
  830.    static void setDebugOptions(JComponent component, int options) {
  831.       info().setDebugOptions(component, options);
  832.    }
  833.  
  834.    public static void setFlashColor(Color flashColor) {
  835.       info().flashColor = flashColor;
  836.    }
  837.  
  838.    public static void setFlashCount(int flashCount) {
  839.       info().flashCount = flashCount;
  840.    }
  841.  
  842.    public static void setFlashTime(int flashTime) {
  843.       info().flashTime = flashTime;
  844.    }
  845.  
  846.    public void setFont(Font aFont) {
  847.       if (this.debugLog()) {
  848.          info().log(this.toShortString() + " Setting font: " + aFont);
  849.       }
  850.  
  851.       this.graphics.setFont(aFont);
  852.    }
  853.  
  854.    public static void setLogStream(PrintStream stream) {
  855.       info().stream = stream;
  856.    }
  857.  
  858.    public void setPaintMode() {
  859.       if (this.debugLog()) {
  860.          info().log(this.toShortString() + " Setting paint mode");
  861.       }
  862.  
  863.       this.graphics.setPaintMode();
  864.    }
  865.  
  866.    public void setXORMode(Color aColor) {
  867.       if (this.debugLog()) {
  868.          info().log(this.toShortString() + " Setting XOR mode: " + aColor);
  869.       }
  870.  
  871.       this.graphics.setXORMode(aColor);
  872.    }
  873.  
  874.    static int shouldComponentDebug(JComponent component) {
  875.       DebugGraphicsInfo info = info();
  876.       if (info == null) {
  877.          return 0;
  878.       } else {
  879.          Container container = component;
  880.  
  881.          int debugOptions;
  882.          for(debugOptions = 0; container != null && container instanceof JComponent; container = ((Component)container).getParent()) {
  883.             debugOptions |= info.getDebugOptions((JComponent)container);
  884.          }
  885.  
  886.          return debugOptions;
  887.       }
  888.    }
  889.  
  890.    final void sleep(int mSecs) {
  891.       try {
  892.          Thread.sleep((long)mSecs);
  893.       } catch (Exception var2) {
  894.       }
  895.  
  896.    }
  897.  
  898.    String toShortString() {
  899.       StringBuffer buffer = new StringBuffer("Graphics" + (this.isDrawingBuffer() ? "<B>" : "") + "(" + this.graphicsID + "-" + this.debugOptions + ")");
  900.       return buffer.toString();
  901.    }
  902.  
  903.    public void translate(int x, int y) {
  904.       if (this.debugLog()) {
  905.          info().log(this.toShortString() + " Translating by: " + new Point(x, y));
  906.       }
  907.  
  908.       this.xOffset += x;
  909.       this.yOffset += y;
  910.       this.graphics.translate(x, y);
  911.    }
  912. }
  913.